package gwt.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ScrollEvent;
import com.google.gwt.event.dom.client.ScrollHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.*;

/**
 * Created by swootton on 26/03/14.
 */
public class RepositoryLoginPanel extends VerticalPanel {

    private ListBox listBox;

    public RepositoryLoginPanel() {

        super();

        Command cmd = new Command() {
            public void execute() {
                Window.alert("You selected a menu item!");
            }
        };

        getElement().getStyle().setProperty("backgroundColor", "#ECECEA");
        setSpacing(10);

        setSize("100%", "100%");

        Image img = new Image(GWT.getModuleBaseURL()+"../images/login.png");
        img.getElement().getStyle().setProperty("border", "black solid 1px");
        img.setSize("40%","40%");

        Label title = new Label("Login");
        title.getElement().getStyle().setProperty("border","black solid 1px");


        HorizontalPanel header = new HorizontalPanel();
        header.getElement().getStyle().setProperty("border", "black solid 1px");
        header.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
        header.add(img);
        header.add(title);

        add(header);

        //HorizontalPanel repositories = new HorizontalPanel();
        ScrollPanel scrollPanel = new ScrollPanel();
        scrollPanel.getElement().getStyle().setProperty("border", "black solid 1px");
        scrollPanel.setSize("250px", "100px");

        scrollPanel.addScrollHandler(new ScrollHandler() {
            @Override
            public void onScroll(ScrollEvent event) {
                GWT.log("onScroll "+event.toString());
            }
        });

        //add(scrollPanel);

        VerticalPanel repositoryPanel = new VerticalPanel();
        Label repositoryLabel = new Label("Repositories:");
        repositoryPanel.add(repositoryLabel);

        listBox = new ListBox(false);
        //String[] listTypes = String[];
        listBox.setWidth("250px");

        listBox.addItem("Repository A");
        listBox.addItem("Repository B");
        listBox.addItem("Repository C");
        listBox.addItem("Repository D");
        listBox.addItem("Repository E");
        listBox.addItem("Repository F");
        listBox.addItem("Repository G");

        listBox.setVisibleItemCount(5);

        repositoryPanel.add(listBox);

        listBox.addChangeHandler(new ChangeHandler() {
            public void onChange(ChangeEvent event) {
                GWT.log("listbox change even: " + listBox.getSelectedIndex());
            }
        });


        VerticalPanel userData = new VerticalPanel();

        VerticalPanel usernamePanel = new VerticalPanel();
        Label usernameLabel = new Label("Username:");
        usernamePanel.add(usernameLabel);

        TextBox usernameTextBox = new TextBox();
        usernamePanel.add(usernameTextBox);

        VerticalPanel passwordPanel = new VerticalPanel();
        Label pwdLabel = new Label("Password:");
        passwordPanel.add(pwdLabel);

        TextBox pwdTextBox = new TextBox();
        passwordPanel.add(pwdTextBox);

        Button button = new Button();
        button.setText("Login");

        add(repositoryPanel);
        add(usernamePanel);
        add(passwordPanel);
        add(button);
    }
}
